package top.lixunda.demo.seata.feign;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import top.lixunda.demo.seata.common.constant.ServerName;
import top.lixunda.demo.seata.common.controller.MessageObject;
import top.lixunda.demo.seata.common.entity.DbAccount;

import java.util.List;

/**
 * @author LiXunda
 * @version time:2019/10/25 9:41
 * <p>
 * 用户的feign调用客户端，主要用于在生成订单时减少用户账户余额
 */
@FeignClient(name = ServerName.SN_ACCOUNT)
@RequestMapping("/account")
public interface AccountClient {

    /**
     * 扣除用户的账户余额
     *
     * @param accountId 用户账户唯一id
     * @param money     扣除的余额
     * @return 返回是否成功，成功返回为true的ObjectMessage，失败返回为false的ObjectMessage
     */
    @GetMapping("/deductionById")
    MessageObject<Boolean> deduction(@RequestParam("accountId") int accountId, @RequestParam("money") double money);

    /**
     * 查询所有用户信息
     *
     * @return DBAccount列表
     */
    @GetMapping("/queryAll")
    MessageObject<List<DbAccount>> queryAll();

}
